package otherObjects;

/*L'objet DBConn sera partag� dans l'application (voir le ServletContext)
 * */

import java.sql.*;

public class DBConn {

	Connection connexion = null ;
	Statement instruction = null ;
	String user = "" ;
	String password = "";
	ResultSet rs = null;
	Integer up= null;

	public DBConn(){
		try {
			Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
			connexion = DriverManager.getConnection("jdbc:derby:live", user, password);
		}
		catch ( ClassNotFoundException k)
		{
			System.out.println("Erreur lors du chargement du pilote : " + k);
		}
		catch (SQLException sqle)
		{
			System.out.print("Erreur SQL : " + sqle);
		}

	}

	public ResultSet executeQuery(String sql) {
		rs = null;
		try {
			Statement stmt = connexion.createStatement ();
			rs = stmt.executeQuery(sql);
		}
		catch(SQLException ex) {
			System.out.println("aq.executeQuery: " + ex.getMessage());
		}
		return rs;
	}

	public int executeUpdate(String sql) {
		up = null;
		try {
			Statement stmt = connexion.createStatement();
			up = stmt.executeUpdate(sql);
		}
		catch(SQLException ex) {
			System.out.println(" aq.executeUpdate: " + ex.getMessage());
		}
		return up;
	}

	public Connection getConnexion() {
		return connexion;
	}

	public void setConnexion(Connection connexion) {
		this.connexion = connexion;
	}

	public Statement getInstruction() {
		return instruction;
	}

	public void setInstruction(Statement instruction) {
		this.instruction = instruction;
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public ResultSet getRs() {
		return rs;
	}

	public void setRs(ResultSet rs) {
		this.rs = rs;
	}

} 
